package com.atguigu.gmall.cart.mapper;

import com.atguigu.gmall.model.cart.CartInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 购物车Mapper映射
 */
@Mapper
public interface CartInfoMapper extends BaseMapper<CartInfo> {
    /**
     * 修改全部记录的上下架状态
     * @param status
     * @param username
     */
    @Update("UPDATE cart_info SET is_checked = #{status} WHERE user_id = #{username}")
    public int updateCheckAll(@Param("status") Short status,@Param("username") String username);

    /**
     * 修改单条记录的上下架状态
     * @param id
     * @param status
     * @param username
     * @return
     */
    @Update("UPDATE cart_info SET is_checked = #{status} WHERE user_id = #{username} AND id = #{id}")
    int updateCheck(@Param("id") Long id,@Param("status") Short status,@Param("username") String username);

    /**
     * 修改购物车中商品数量
     * @param id
     * @param num
     * @param username
     */
    @Update("UPDATE cart_info SET sku_num = #{num} WHERE user_id = #{username} AND id = #{id}")
    int updateCartInfoNum(@Param("id") Long id,@Param("num") Integer num,@Param("username") String username);

}
